<?php
$pg = 'login';

$usersDao = new UsersDao();

if ( isset($_POST['submit']) && $_POST['submit'] == "Entra")
{

    $user = $usersDao->check($connection, $_POST['user'], $_POST['pass']);

    if ($user->getId() != "")
    {
        $_SESSION['user'] = $user->getUsername();
        $_SESSION['pass'] = $user->getPassword();
        $smarty->Assign("utente", $_SESSION['user']);
		
		if (isset($_GET['ajax']) && $_GET['ajax'] == "on")
		{
			echo 1;
		}
		else
		{
			header("Location: ./?pg=home");			
		}


    }
    else
    {
    	if (isset($_GET['ajax']) && $_GET['ajax'] == "on")
		{
			echo -1;
		}
        $smarty->Assign("utente", "");
		
    }
}

if ( isset ($_GET['logout']))
{
    $smarty->Assign("utente", "");
    unset ($_SESSION['user']);
    unset ($_SESSION['pass']);
}
?>
